/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pracamagisterska;

import java.awt.Color;
import java.sql.SQLException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.JComponent;
import javax.swing.JDesktopPane;
import javax.swing.JOptionPane;

public class PersonDetails extends ModalityInternalFrame {

    private static final String EMAIL_PATTERN = "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@" + "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
    private DatabaseThread db;
    private ReviewList item;
    private final org.jbundle.thin.base.screen.jcalendarbutton.JCalendarButton jCalendarButton1;
    private JComponent parent;
    private boolean type = false;

    public PersonDetails(JComponent parent, ReviewList item, DatabaseThread db, boolean type) {
        super(parent, item, db, type);
        this.parent = parent;
        this.item = item;
        this.db = db;
        this.type = type;
        initComponents();

        jCalendarButton1 = new org.sourceforge.jcalendarbutton.JCalendarButton();
        jCalendarButton1.addPropertyChangeListener(new java.beans.PropertyChangeListener() {

            @Override
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                if (evt.getNewValue() instanceof Date) {
                    setDate((Date) evt.getNewValue());
                }
            }

            private void setDate(Date date) {
                DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
                jFormattedTextField1.setText(dateFormat.format(date));
            }
        });
        this.add(jCalendarButton1);
        jCalendarButton1.setLocation(310, 266);
        jCalendarButton1.setSize(34, 34);
        if (item != null) {
            jButton3.setEnabled(false);
            RefillPersonDetails();
        } 
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    private boolean validateName(String name) {
        if (name != null && name.length() > 2) {
            jLabel12.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/childish_alert_small.png")));
            jTextField1.setBackground(Color.white);
            return true;
        }
        jLabel12.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/childish_cross_small2.png")));
        jTextField1.setBackground(Color.YELLOW);
        return false;
    }

    private boolean validateSurname(String name) {
        if (name != null && name.length() > 3) {
            jLabel13.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/childish_alert_small.png")));
            jTextField2.setBackground(Color.white);
            return true;
        }
        jLabel13.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/childish_cross_small2.png")));
        jTextField2.setBackground(Color.YELLOW);
        return false;
    }

    private boolean validateDate(String data) throws ParseException {
        if (data != null) {
            DateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
            Date curdate = new Date();
            Date date = sdf.parse(data);
            if (date.before(curdate)) {
                jFormattedTextField1.setBackground(Color.white);
                jLabel14.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/childish_alert_small.png")));
                return true;
            }
        }
        jFormattedTextField1.setBackground(Color.YELLOW);
        jLabel14.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/childish_cross_small2.png")));
        return false;

    }

    private boolean validateBirthplace(String place) {
        if (place != null && place.length() > 3) {
            jLabel15.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/childish_alert_small.png")));
            jTextField4.setBackground(Color.white);
            return true;
        }
        jLabel15.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/childish_cross_small2.png")));
        jTextField4.setBackground(Color.YELLOW);
        return false;
    }

    private boolean validateNationality(String nat) {
        if (nat != null && nat.length() > 3) {
            jLabel16.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/childish_alert_small.png")));
            jTextField5.setBackground(Color.white);
            return true;
        }
        jLabel16.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/childish_cross_small2.png")));
        jTextField5.setBackground(Color.YELLOW);
        return false;
    }

    private boolean validateAddress(String address) {
        if (address != null && address.length() > 6) {
            jLabel17.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/childish_alert_small.png")));
            jTextField6.setBackground(Color.white);
            return true;
        }
        jLabel17.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/childish_cross_small2.png")));
        jTextField6.setBackground(Color.YELLOW);
        return false;
    }

    private boolean validateDoc(String doc) {
        if (doc != null && doc.length() > 4) {
            jLabel18.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/childish_alert_small.png")));
            jTextField7.setBackground(Color.white);
            return true;
        }
        jLabel18.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/childish_cross_small2.png")));
        jTextField7.setBackground(Color.YELLOW);
        return false;
    }

    private boolean validateMail(String mail) {
        Pattern pattern = Pattern.compile(EMAIL_PATTERN);
        Matcher matcher = pattern.matcher(mail);
        if (mail.length()==0 || matcher.matches()) {
            jLabel19.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/childish_alert_small.png")));
            jTextField8.setBackground(Color.white);
            return true;
        }
        jLabel19.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/childish_cross_small2.png")));
        jTextField8.setBackground(Color.YELLOW);
        return false;
    }

    private void RefillPersonDetails() {
        jTextField1.setText(item.getName());
        jTextField2.setText(item.getSurname());
        if (item.getSex().equals("M")) {
            jRadioButton2.setSelected(true);
        }
        jFormattedTextField1.setText(item.getBirthdate());
        jTextField3.setText(item.getId() + "");
        jTextField4.setText(item.getBirthplace());
        jTextField5.setText(item.getNationality());
        jTextField6.setText(item.getAddress());
        jTextField7.setText(item.getIdentity());
        jTextField8.setText(item.getMail());
        if (item.isNews()) {
            jRadioButton3.setSelected(true);
        }
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        buttonGroup2 = new javax.swing.ButtonGroup();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jTextField1 = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jTextField2 = new javax.swing.JTextField();
        jTextField4 = new javax.swing.JTextField();
        jTextField5 = new javax.swing.JTextField();
        jTextField6 = new javax.swing.JTextField();
        jTextField7 = new javax.swing.JTextField();
        jTextField8 = new javax.swing.JTextField();
        jRadioButton1 = new javax.swing.JRadioButton();
        jRadioButton2 = new javax.swing.JRadioButton();
        jRadioButton3 = new javax.swing.JRadioButton();
        jRadioButton4 = new javax.swing.JRadioButton();
        jLabel11 = new javax.swing.JLabel();
        jFormattedTextField1 = new javax.swing.JFormattedTextField();
        jButton2 = new javax.swing.JButton();
        jTextField3 = new javax.swing.JTextField();
        jLabel20 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        jLabel19 = new javax.swing.JLabel();
        jLabel18 = new javax.swing.JLabel();
        jButton3 = new javax.swing.JButton();

        setIconifiable(true);
        setToolTipText("");
        setMaximumSize(new java.awt.Dimension(480, 650));
        setMinimumSize(new java.awt.Dimension(480, 650));
        setPreferredSize(new java.awt.Dimension(420, 650));

        jLabel1.setText("Imię:");

        jLabel2.setText("Nazwisko:");

        jLabel3.setText("Płeć:");
        jLabel3.setToolTipText("");

        jLabel4.setText("Data urodzenia:");

        jLabel5.setText("Miejsce urodzenia:");

        jLabel6.setText("Narodowość:");

        jLabel7.setText("Adres:");

        jButton1.setText("Zapisz");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jLabel8.setText("Nr dokumentu:");

        jLabel9.setText("E-mail:");

        jLabel10.setText("Zgoda na newsletter:");

        buttonGroup1.add(jRadioButton1);
        jRadioButton1.setSelected(true);
        jRadioButton1.setText("Kobieta");

        buttonGroup1.add(jRadioButton2);
        jRadioButton2.setText("Mężczyzna");

        buttonGroup2.add(jRadioButton3);
        jRadioButton3.setText("Tak");

        buttonGroup2.add(jRadioButton4);
        jRadioButton4.setSelected(true);
        jRadioButton4.setText("Nie");

        jLabel11.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/clients.png"))); // NOI18N

        jFormattedTextField1.setEditable(false);
        jFormattedTextField1.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter(new java.text.SimpleDateFormat("dd-MM-yyyy"))));

        jButton2.setText("Anuluj");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jTextField3.setEditable(false);
        jTextField3.setEnabled(false);

        jLabel20.setText("ID:");

        jLabel12.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/childish_alert_small.png"))); // NOI18N
        jLabel12.setToolTipText("To pole nie może być puste");
        jLabel12.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);

        jLabel13.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/childish_alert_small.png"))); // NOI18N
        jLabel13.setToolTipText("To pole nie może być puste");

        jLabel14.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/childish_alert_small.png"))); // NOI18N
        jLabel14.setToolTipText("Format: yyyy-MM-dd");

        jLabel15.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/childish_alert_small.png"))); // NOI18N
        jLabel15.setToolTipText("To pole nie może być puste");

        jLabel16.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/childish_alert_small.png"))); // NOI18N
        jLabel16.setToolTipText("To pole nie może być puste");

        jLabel17.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/childish_alert_small.png"))); // NOI18N
        jLabel17.setToolTipText("To pole nie może być puste");

        jLabel19.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/childish_alert_small.png"))); // NOI18N
        jLabel19.setToolTipText("Adres e-mail powinnien zawierać domenę / To pole może być puste");

        jLabel18.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/childish_alert_small.png"))); // NOI18N
        jLabel18.setToolTipText("To pole nie może być puste");

        jButton3.setText("Wybierz");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(jLabel11)
                .addGap(140, 140, 140))
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel4)
                            .addComponent(jLabel3)
                            .addComponent(jLabel6)
                            .addComponent(jLabel7)
                            .addComponent(jLabel9)
                            .addComponent(jLabel10)
                            .addComponent(jLabel5)
                            .addComponent(jLabel8)
                            .addComponent(jLabel2)
                            .addComponent(jLabel1)
                            .addComponent(jLabel20))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(jTextField6)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(jLabel17))
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(jFormattedTextField1)
                                        .addGroup(layout.createSequentialGroup()
                                            .addComponent(jRadioButton2)
                                            .addGap(18, 18, 18)
                                            .addComponent(jRadioButton1)))
                                    .addGap(70, 70, 70)
                                    .addComponent(jLabel14))
                                .addGroup(layout.createSequentialGroup()
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jTextField4)
                                        .addComponent(jTextField5))
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jLabel16, javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addComponent(jLabel15, javax.swing.GroupLayout.Alignment.TRAILING)))
                                .addGroup(layout.createSequentialGroup()
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jTextField7)
                                        .addComponent(jTextField8))
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jLabel19, javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addComponent(jLabel18, javax.swing.GroupLayout.Alignment.TRAILING)))
                                .addGroup(layout.createSequentialGroup()
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addGroup(layout.createSequentialGroup()
                                            .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                            .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addComponent(jTextField1, javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jTextField2, javax.swing.GroupLayout.Alignment.LEADING))
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jLabel13, javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addComponent(jLabel12, javax.swing.GroupLayout.Alignment.TRAILING))))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jRadioButton3)
                                .addGap(58, 58, 58)
                                .addComponent(jRadioButton4))))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(105, 105, 105)
                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(35, 35, 35)
                        .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(24, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jLabel11)
                .addGap(11, 11, 11)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel12, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jButton3))
                                .addGap(4, 4, 4)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel1))))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel2))
                            .addComponent(jLabel13))
                        .addGap(7, 7, 7)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jRadioButton2)
                                    .addComponent(jRadioButton1)
                                    .addComponent(jLabel3))
                                .addGap(9, 9, 9)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jFormattedTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel4)))
                            .addComponent(jLabel14))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel5))
                            .addComponent(jLabel15))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel6))
                            .addComponent(jLabel16))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel7))
                            .addComponent(jLabel17)))
                    .addComponent(jLabel20))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jTextField7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel8))
                    .addComponent(jLabel18))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jTextField8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel9))
                    .addComponent(jLabel19))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jRadioButton3)
                    .addComponent(jRadioButton4)
                    .addComponent(jLabel10))
                .addGap(44, 44, 44)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton2)
                    .addComponent(jButton1))
                .addContainerGap(44, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        ModalityInternalFrame wrg;
        if(parent instanceof Review) wrg = new Warning(this, "Czy porzucić zmiany ?",null, false);
        else wrg = new Warning(this, "Czy porzucić zmiany ?",null, true);
        JDesktopPane desktop = JOptionPane.getDesktopPaneForComponent(this);
        desktop.add(wrg);
        wrg.show();
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        try {
            int status = 0;
            if (validateName(jTextField1.getText())) {
                status++;
            }
            if (validateSurname(jTextField2.getText())) {
                status++;
            }
            if (validateDate(jFormattedTextField1.getText())) {
                status++;
            }
            if (validateBirthplace(jTextField4.getText())) {
                status++;
            }
            if (validateNationality(jTextField5.getText())) {
                status++;
            }
            if (validateAddress(jTextField6.getText())) {
                status++;
            }
            if (validateDoc(jTextField7.getText())) {
                status++;
            }
            if (validateMail(jTextField8.getText())) {
                status++;
            }
            if (status == 8) {
                ModalityInternalFrame wrg;
                if(parent instanceof Review) wrg = new Warning(this, "Czy chcesz zapisać zmiany ?", db,false);
                else wrg = new Warning(this, "Czy chcesz zapisać zmiany ?", db,true);
                JDesktopPane desktop = JOptionPane.getDesktopPaneForComponent(this);
                desktop.add(wrg);
                wrg.show();
            }
        } catch (ParseException ex) {
            Logger.getLogger(PersonDetails.class.getName()).log(Level.SEVERE, null, ex);
        }

    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        ModalityInternalFrame pr = new PersonReview(this, db);
        JDesktopPane desktop = JOptionPane.getDesktopPaneForComponent(this);
        desktop.add(pr);
        pr.show();
    }//GEN-LAST:event_jButton3ActionPerformed

    protected void selectFromList(ReviewList item) {
        getGlassPane().setVisible(false);
        setChildFrame(null);
        jTextField1.setText(item.getName());
        jTextField2.setText(item.getSurname());
        if (item.getSex().equals("M")) {
            jRadioButton2.setSelected(true);
        }
        jFormattedTextField1.setText(item.getBirthdate());
        jTextField3.setText(item.getId() + "");
        jTextField4.setText(item.getBirthplace());
        jTextField5.setText(item.getNationality());
        jTextField6.setText(item.getAddress());
        jTextField7.setText(item.getIdentity());
        jTextField8.setText(item.getMail());
        if (item.isNews()) {
            jRadioButton3.setSelected(true);
        }
    }

    protected void childparentClosing(boolean status) throws SQLException {
        if (!status) { // nic nie rób
            getGlassPane().setVisible(false);
            setChildFrame(null);
            this.dispose();
            ((Review) parent).childClosing();
        } else { // aktualizuj dane lub dodaj
            String sex = "M";
            int id = 0;
            ReviewList neww = null;
            if (jRadioButton1.isSelected()) {
                sex = "F";
            }
            if (!jTextField3.getText().equals("")) {
                id = Integer.parseInt(jTextField3.getText());
            } else {
                id = 0;
            }
            neww = new ReviewList(id, jTextField1.getText(), jTextField2.getText(), jTextField8.getText(), sex, jTextField4.getText(), jFormattedTextField1.getText(), jTextField5.getText(), jTextField6.getText(), jTextField7.getText(), jRadioButton3.isSelected());
            if (db.PersonDetails_update(neww, ((Review) parent).index, type)) {
                ((Review) parent).refresh();
                getGlassPane().setVisible(false);
                setChildFrame(null);
                this.dispose();
                ((Review) parent).childClosing();
            } else {
                ModalityInternalFrame er = new Error(this, "Ktoś już legitymował się tym dokumentem!");
                JDesktopPane desktop = JOptionPane.getDesktopPaneForComponent(this);
                desktop.add(er);
                er.show();
            }
        }
    }
    
    protected void childReviewClosing(boolean status) throws SQLException {
        if (!status) { // nic nie rób
            getGlassPane().setVisible(false);
            setChildFrame(null);
            this.dispose();
            ((PersonReview) parent).childClosing();                    
        } else { // aktualizuj dane lub dodaj
            String sex = "M";
            int id = 0;
            ReviewList neww = null;
            if (jRadioButton1.isSelected()) {
                sex = "F";
            }
            id = Integer.parseInt(jTextField3.getText());
            neww = new ReviewList(id, jTextField1.getText(), jTextField2.getText(), jTextField8.getText(), sex, jTextField4.getText(), jFormattedTextField1.getText(), jTextField5.getText(), jTextField6.getText(), jTextField7.getText(), jRadioButton3.isSelected());
            if (db.PersonDetails_update(neww, 0, false)) {
                getGlassPane().setVisible(false);
                setChildFrame(null);
                this.dispose();
                ((PersonReview) parent).childClosing();  
                ((PersonReview) parent).refresh();
            } else {
                ModalityInternalFrame er = new Error(this, "Ktoś już legitymował się tym dokumentem!");
                JDesktopPane desktop = JOptionPane.getDesktopPaneForComponent(this);
                desktop.add(er);
                er.show();
            }
        }
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.ButtonGroup buttonGroup2;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JFormattedTextField jFormattedTextField1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JRadioButton jRadioButton1;
    private javax.swing.JRadioButton jRadioButton2;
    private javax.swing.JRadioButton jRadioButton3;
    private javax.swing.JRadioButton jRadioButton4;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JTextField jTextField4;
    private javax.swing.JTextField jTextField5;
    private javax.swing.JTextField jTextField6;
    private javax.swing.JTextField jTextField7;
    private javax.swing.JTextField jTextField8;
    // End of variables declaration//GEN-END:variables
}
